#include "cmd_err_code.hpp"

#include "cmd_comm.hpp"

namespace cmd
{
	void AreaId::serialize(Streamer & streamer)
	{
		streamer & _area_id
			     & _area_type;
	}

	const std::string AreaId::to_string() const
	{
		std::ostringstream oss;
		oss << "{area_id: " << (int)_area_id
			<< ", area_type: " << (int)_area_type;
		return oss.str();
	}

	void RoomId::serialize(Streamer & streamer)
	{
		streamer & _area_id
				 & _area_type
				 & _room_id;
	}

	const std::string RoomId::to_string() const
	{
		std::ostringstream oss;
		oss << "{area_id: " << (int)_area_id
			<< ", area_type: " << (int)_area_type
			<< ", room_id: " << (int)_room_id;
		return oss.str();
	}
	
	void TableId::serialize(Streamer & streamer)
	{
		streamer & _area_id
			     & _area_type
				 & _room_id
				 & _table_id;
	}

	const std::string TableId::to_string() const
	{
		std::ostringstream oss;
		oss << "{area_id: " << (int)_area_id
			<< ", area_type: " << (int)_area_type
			<< ", room_id: " << (int)_room_id
			<< ", table_id: " << (int)_table_id;
		return oss.str();
	}
	
	void Position::serialize(Streamer & streamer)
	{
		streamer & _area_id
				 & _room_id
				 & _table_id
				 & _seat_id;
	}

	const std::string Position::to_string() const
	{
		std::ostringstream oss;
		oss << "{area_id: " << (int)_area_id
			<< ", room_id: " << (int)_room_id
			<< ", table_id: " << (int)_table_id
			<< ", seat_id: " << (int)_seat_id;
		return oss.str();
	}
	
	void RoleB::serialize(Streamer & streamer)
	{
		streamer & _id
				 & _sex
				 & _age
				 & _province
				 & _city
				 & _level
				 & _title
				 & _silver
				 & _lost_num
				 & _win_num
				 & _position;
	}

	const std::string RoleB::to_string() const
	{
		std::ostringstream oss;
		oss << "{id: " << _id
			<< ", sex: " << (int)_sex
			<< ", age: " << (int)_age
			<< ", province: " << _province
			<< ", city: " << _city
			<< ", level: " << (int)_level
			<< ", title: " << (int)_title
			<< ", silver: " << _silver
			<< ", lost num: " << _lost_num
			<< ", win num: " << _win_num
			<< ", position: " << _position.to_string();

		return oss.str();
	}
	
	void AreaB::serialize(Streamer & streamer)
	{
		streamer & _id
			     & _role_num;
	}

	const std::string AreaB::to_string() const
	{
		std::ostringstream oss;
		oss << "{id: " << _id.to_string()
			<< ", role_num: " << (int)_role_num;
		return oss.str();
	}
	
	void RoomB::serialize(Streamer & streamer)
	{
		streamer & _id
			     & _online;
	}

	const std::string RoomB::to_string() const
	{
		std::ostringstream oss;
		oss << "{id: " << (int)_id
			<< ", online: " << (int)_online;
		return oss.str();
	}
	
	void TableB::serialize(Streamer & streamer)
	{
		streamer & _id
			     & _online
				 & _role_list;
	}

	const std::string TableB::to_string() const
	{
		std::ostringstream oss;
		oss << "{id: " << (int)_id
			<< ", role_num: " << (int)_online;
		return oss.str();
	}

	void Card::serialize(Streamer & streamer)
	{
		streamer & _id
			     & _type;
	}

	const std::string Card::to_string() const
	{
		std::ostringstream oss;
		oss << "{id: " << (int)_id
			<< ", type: " << (int)_type
			<< "}";
		return oss.str();
	}

	void CmdHead::serialize(Streamer & streamer)
	{
		streamer & _length
			     & _magic
		         & _cmd_0
			     & _cmd_1
				 & _rid;
	}

	const std::string CmdHead::to_string() const
	{
		std::ostringstream oss;

		oss << "head: {length: " << _length
			<< ", magic: " << _magic
			<< ", cmd_0: " << (int) _cmd_0
			<< ", cmd_1: " << (int) _cmd_1
			<< ", rid: " << _rid;
		
		return oss.str();
	}

	void SCHead::serialize(Streamer & streamer)
	{
		CmdHead::serialize(streamer);
		streamer & _err_code;
	}

	const std::string SCHead::to_string() const
	{
		std::ostringstream oss;

		oss << CmdHead::to_string()
			<< " body: {err_code: " << (int)_err_code
			<< "(" << game_err_to_str(_err_code)
			<< ")}";
		return oss.str();
	}
};

